/**
 * Created by zhourh on 2018/5/22.
 */
public class HammingDistance {

    public static void main(String[] args) {
        System.out.println(new HammingDistance().hammingDistance(1, 4));
    }
    public int hammingDistance(int x, int y) {
        int t = x ^ y;
        int distance = 0;
        while (t != 0) {
            if ((t & 0x01) == 0x01) {
                distance++;
            }
            t = t >> 1;
        }

        return distance;
    }
}
